<template>
  <div class="ContrastWard">
    <div class="pubBig Medical">
      <div class="h0">
        <p class="lt"></p>
      </div>
      <div class="LeftMain">
        <div>
          <p class="p1">用户(支持一对零/一对一/一对多)(双击可删除选择的用户)</p>
          <div class="threeBox pucLab clearfix">
            <p>
              <label>拼音码/名称：</label>
              <input
                v-model="model_jmC"
                type="text"
                class="form-control"
                style="width:120px"
              />
            </p>
            <p>
              <button class="btn btn-default" @click="queryz_yh()">查询</button>
            </p>
          </div>
          <div class="Tb">
            <table class="table table-bordered">
              <thead>
                <tr>
                  <th>用户代码</th>
                  <th>用户名称</th>
                </tr>
              </thead>
              <tbody>
                <tr
                  v-for="(item, index) in model_query_yh"
                  :key="index"
                  @click="openDetails(item, index)"
                  :class="{ selGreen: changeSelectStyle == index }"
                >
                  <td>{{ item.user_id }}</td>
                  <td>{{ item.user_name }}</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
        <div>
          <p class="p1">用户病区记录</p>
          <div class="Tb">
            <table class="table table-bordered">
              <thead>
                <tr>
                  <th>病区代码</th>
                  <th>病区名称</th>
                </tr>
              </thead>
              <tbody>
                <tr
                  v-for="(item, index) in model_query_dz"
                  :key="index"
                  @click="openDetails2(item, index)"
                  :class="{ selGreen: changeSelectStyle2 == index }"
                >
                  <td>{{ item.id }}</td>
                  <td>{{ item.name }}</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
      <div class="RightMain">
        <p class="p1">病区(双击要添加的行即可添加到选择的用户病区记账项目中)</p>
        <div class="threeBox pucLab clearfix">
          <p>
            <label>拼音码/名称/编号：</label>
            <input type="text" class="form-control" style="width:150px" />
          </p>
          <p>
            <button class="btn btn-default" @click="queryz_ks()">查询</button>
          </p>
        </div>
        <div class="Tb">
          <table class="table table-bordered">
            <thead>
              <tr>
                <th>
                  <input id="allboxs" onclick="allcheck()" type="checkbox" />
                </th>

                <th>病区代码</th>
                <th>病区名称</th>
              </tr>
            </thead>
            <tbody>
              <tr
                v-for="(item, index) in model_query_ks"
                :key="index"
                :class="{ selGreens: changeSelectStyle1 == index }"
              >
                <td>
                  <input
                    name="boxs"
                    type="checkbox"
                    @click="openDetails1(item, index)"
                  />
                </td>
                <td>{{ item.id }}</td>
                <td>{{ item.name }}</td>
              </tr>
            </tbody>
          </table>
          <button class="btn uuu" @click="savez()">对照</button>
          <button class="btn ttt" @click="deletez()">删除</button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "Bedinformation",
  data() {
    return {
      msg: "SystemManagement 下的 Bedinformation",
      model_operation_levelc: "",
      //

      model_born: "", //出生日期
      model_contact_phone: "", //联系人电话
      model_entrydate: "", //入职日期
      model_idnumber: "", //身份证号
      model_last_login_address: "", //最后登录地址
      model_last_login_time: "", //最后登录时间
      model_nation: "", //民族代码
      model_photo: "", //照片头像
      model_post: "", //用户职位(医生/护士/收费员/其它)
      model_registertime: "", //注册日期
      model_sex: "", //性别代码
      model_title: "", //职称代码
      model_user_id: "", //用户代码
      model_user_name: "", //用户姓名
      model_user_no: "", //用户工号
      model_user_pass: "", //用户密码
      model_user_status: "", //用户状态

      model_code: "", //科室编码
      model_flag: "", //是否使用标志
      model_hospital_id: "", //医院编号
      model_id: "", //病区代码
      model_name: "", //病区名称
      model_pym: "", //拼音码
      model_section_class: "", //科室类型
      model_storage_flag: "", //药库标志
      model_store_flag: "", //药房标志

      model_id: "", //序号
      model_section_id: "", //病区代码
      model_user_id: "", //用户代码

      model_idu: "",
      model_user_idu: "",
      model_ward_idu: "",

      //下拉框
      model_select_id: [], //序号
      model_select_section: [], //病区代码
      model_select_ward_id: [], //病区代码

      LIST1: [],
      //
      model_select_ward_idC: "",

      model_jmC: "",
      model_jmC1: "",
      model_query: [], //查询结果
      model_query_ks: [], //查询结果2
      model_query_dz: [],
      model_query_yh: [],
      changeSelectStyle: "",
      changeSelectStyle1: "",
      changeSelectStyle2: "",
      bed_info: {
        columns: [
          { field: "hospital_id", title: "医院编号" },
          { field: "code", title: "床位编码" },
          { field: "section_id", title: "病区代码" },
          { field: "ward_id", title: "病区代码" },
          { field: "room_no", title: "房间号" },
          { field: "id", title: "床位号" },
          { field: "name", title: "床位名称" },
          { field: "bed_status", title: "床位状态" },
          { field: "patient_id", title: "当前住院号" },
        ],
        data: [],
      },
      currentPage: 1,
      total: 0,
      pagesize: 13,
    };
  },
  methods: {
    openDetails(row, index) {
      this.model_born = row.born; //出生日期
      this.model_contact_phone = row.contact_phone; //联系人电话
      this.model_entrydate = row.entrydate; //入职日期
      this.model_idnumber = row.idnumber; //身份证号
      this.model_last_login_address = row.last_login_address; //最后登录地址
      this.model_last_login_time = row.last_login_time; //最后登录时间
      this.model_nation = row.nation; //民族代码
      this.model_photo = row.photo; //照片头像
      this.model_post = row.post; //用户职位(医生/护士/收费员/其它)
      this.model_registertime = row.registertime; //注册日期
      this.model_sex = row.sex; //性别代码
      this.model_title = row.title; //职称代码
      this.model_user_id = row.user_id; //用户代码
      this.model_user_name = row.user_name; //用户姓名
      this.model_user_no = row.user_no; //用户工号
      this.model_user_pass = row.user_pass; //用户密码
      this.model_user_status = row.user_status; //用户状态

      this.queryz();

      this.changeSelectStyle = index;
      console.log(row);
    },
    handleChange(val) {
      console.log(val);
    },
    openDetails1(row, index) {
      this.model_code = row.code; //科室编码
      this.model_flag = row.flag; //是否使用标志
      this.model_hospital_id = row.hospital_id; //医院编号
      this.model_id = row.id; //病区代码
      this.model_name = row.name; //病区名称
      this.model_pym = row.pym; //拼音码
      this.model_section_class = row.section_class; //科室类型
      this.model_storage_flag = row.storage_flag; //药库标志
      this.model_store_flag = row.store_flag; //药房标志

      this.model_ward_id = row.id;
      if (this.LIST1.indexOf(row.id) == -1) {
        this.LIST1.push(row.id);
      } else {
        this.LIST1.splice(this.LIST1.indexOf(row.id), 1);
      }

      this.changeSelectStyle1 = index;
      console.log(row);
    },
    openDetails2(row, index) {
      this.model_id = row.id; //序号
      this.model_section_id = row.section_id; //病区代码
      this.model_user_id = row.user_id; //用户代码
      this.model_idu = row.rid;
      this.changeSelectStyle2 = index;

      console.log(row);
    },
    buttonAdd() {},
    handleChange(val) {
      console.log(val);
    },

    handleChange(val) {
      console.log(val);
    },
    //主表保存
    savez() {
      var data = {
        model: "11.综合维护-用户与病区对照",
        code: "11151",
        input: {
          user_id: this.model_user_id, //用户代码
          // "ward_id": this.model_ward_id,//病区代码
          ward: this.LIST1, //病区代码
        },
      };
      this.$post("CloudHIS/Business_Handle", data)
        .then((res) => {
          if (res.code == 0) {
            console.log(res);
            this.$message({ message: res.msg, type: "success" });
            this.queryz();
            this.addMasterUser();
          } else {
            this.$message({ showClose: true, message: res.msg, type: "error" });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //删除主表信息
    deletez() {
      var data = {
        model: "11.综合维护-用户与病区对照",
        code: "11153",
        input: {
          // model_idu: "",
          // model_user_idu: "",
          // model_ward_idu: "",
          id: this.model_idu,
        },
      };
      this.$post("CloudHIS/Business_Handle", data)
        .then((res) => {
          if (res.code == 0) {
            this.$message({ message: res.msg, type: "success" });
            this.queryz();
          } else {
            this.$message({ showClose: true, message: res.msg, type: "error" });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //主表查询
    queryz() {
      this.model_query_dz = [];
      var data = {
        model: "11.综合维护-用户与病区对照",
        code: "11152",
        input: {
          user_id: this.model_user_id ? this.model_user_id : "-1",
        },
      };
      this.$post("CloudHIS/Business_Handle", data)
        .then((res) => {
          this.model_query_dz = res.data;
          console.log("查询结果");
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },

    queryz_yh() {
      this.model_query_yh = [];
      var data = {
        model: "11.综合维护-用户信息",
        code: "11132",
        input: {
          jm: this.model_jmC ? this.model_jmC : "",
          title: "-1", //职称代码
          sex: "-1", //性别代码
          nation: "-1", //民族代码
          model_entrydate_start: "1990-01-01", //入职日期
          model_entrydate_end: "2060-01-01", //最后登录时间
          user_status: "-1", //用户状态
        },
      };
      console.log(data);
      this.$post("CloudHIS/Business_Handle", data)
        .then((res) => {
          this.model_query_yh = res.data;
          console.log("查询结果");
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    queryz_ks() {
      this.model_query_ks = [];
      var data = {
        model: "11.综合维护-用户与病区对照",
        code: "11154",
        input: {
          jm: this.model_jmC1 ? this.model_jmC1 : "",
          section_class: "-1", //科室类型
          flag: "-1", //是否使用标志
        },
      };
      console.log(data);
      this.$post("CloudHIS/Business_Handle", data)
        .then((res) => {
          this.model_query_ks = res.data;
          console.log("查询结果");
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
    queryG(KeyCode) {
      this.model_query = [];
      var data = {
        code: "get_sys_dict2",
        input: {
          code: KeyCode,
        },
      };
      this.$post("CloudHIS/getRedisDataByCode", data)
        .then((res) => {
          console.log(res);
          for (var i = 0; i < res.data.length; i++) {
            if (res.data[i].keycode == "ward") {
              this.model_select_ward_id = res.data[i].dtl;
            }
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    addMasterUser() {
      this.model_id = ""; //序号
      this.model_section = ""; //病区代码
      this.model_ward_id = ""; //病区代码
    },
    submit(item, index) {
      this.index = index;
      console.log(item);
      var arr = window.document.getElementsByTagName("input");
      for (var i = 0; i < arr.length; i++) {
        var t = arr[i];
        t.index = i;
        t.onkeydown = function(event) {
          if (event.keyCode == 13) {
            var next = this.index + 1;
            arr[next].focus();
          }
        };
      }
    },
    palction() {
      console.log(this.bed_info.data);
    },
    current_change(currentPage) {
      this.currentPage = currentPage;
      this.queryz();
    },
  },
  created() {
    if (this.$route.query.Token) {
      localStorage.setItem("Token", this.$route.query.Token);
    }
    this.msg = this.$route.query;
    this.queryz();
    this.queryz_ks();
    this.queryz_yh();
    var a = ["department", "ward", "State_beds"];
    this.queryG(a);
  },
};
</script>
<style lang="scss">
.ContrastWard {
  .ttt {
    position: fixed;
    background: #e6e6e6;
    left: 608px;
    bottom: 3px;
  }

  .uuu {
    background: #d8e7f6 !important;
    position: fixed;
    width: 22px;
    height: 300px;
    background: #fff;
    left: 690px !important;
    top: 42% !important;
    white-space: normal;
    text-align: center;
    padding: 3px;
    margin-top: -51px;
    border: 1px solid #ccc;
    word-break: break-word;
  }

  .Medical .LeftMain {
    position: absolute;
    left: 0;
    top: 44px;
    bottom: 0;
    width: 500px;
    border-right: 1px solid #ddd;
  }

  .Medical .LeftMain > div {
    height: 50%;
    position: relative;
  }

  .Medical .LeftMain .threeBox p:nth-child(2) {
    margin: 0 7px;
  }

  .Medical .LeftMain .threeBox {
    padding: 10px 10px 0 10px;
  }

  .Medical .LeftMain .threeBox + .Tb {
    top: 80px;
  }

  .Medical .LeftMain .Tb {
    overflow-y: auto;
    position: absolute;
    right: 10px;
    left: 10px;
    bottom: 40px;
    top: 33px;
  }

  .Medical .RightMain {
    padding-left: 498px;
    margin-top: -1px;
    border-left: 1px solid #ddd;
  }

  .Medical .RightMain .threeBox {
    padding: 10px 10px 5px 10px;
  }

  .Medical .RightMain .Tb {
    position: fixed;
    right: 0;
    left: 712px;
    top: 175px;
    bottom: 0;
    overflow-y: auto;
    border-top: 1px solid #ddd;
  }

  .Medical .RightMain .mark2 {
    margin-left: 20px;
  }

  .Medical .RightMain .mark2 label {
    background: none !important;
    border: none !important;
    padding-top: 1px;
    margin-right: 10px;
    cursor: pointer;
  }

  .Medical .RightMain .mark2 label input {
    position: relative;
    top: 2px;
    margin-right: 5px;
  }
}
</style>
